package com.wryyyyy.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ImageUtil {
    public static List<String> getOneUrl(String imagesString, String imagePath) {
        if (imagesString != null) {
            List<String> imgList = Arrays.asList(imagesString.split(",", 0)[0]);
            List<String> relativePath = new ArrayList<>();
            for (String img : imgList) {
                relativePath.add(imagePath + img);
            }
            return relativePath;
        }
        return null;
    }

    public static List<String> getUrls(String imagesString, String imagePath) {
        if (imagesString != null && !imagesString.equals("")) {
            String[] imgList = imagesString.split(",", 0);
            List<String> relativePath = new ArrayList<>();
            for (String img : imgList) {
                relativePath.add(imagePath + img);
            }
            return relativePath;
        }
        return null;
    }

    public static String setImages(String[] urls) {
        StringBuilder images = new StringBuilder("");

        for (String url : urls) {
            images.append(url.substring(url.lastIndexOf('/') + 1)).append(",");
        }

        return images.toString();
    }
}
